package com.example.myapplication.tack_30;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_30.data.NearData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;
import com.google.gson.Gson;

import org.json.JSONObject;

public class DetailsActivity extends AppCompatActivity {
    private ImageView exit;
    private Intent intent;
    private Gson gson;
    private NearData.RowsDTO nearData;
    private ImageView imgUrl;

    private TextView name;
    private TextView name1;
    private TextView address;
    private TextView avgCost;
    private TextView deliveryTime;
    private TextView distance;
    private TextView score;

    private void init() {
        exit = findViewById(R.id.exit);
        imgUrl = findViewById(R.id.imgUrl);

        name = findViewById(R.id.name);
        name1 = findViewById(R.id.name1);
        address = findViewById(R.id.address);
        avgCost = findViewById(R.id.avgCost);
        deliveryTime = findViewById(R.id.deliveryTime);
        distance = findViewById(R.id.distance);
        score = findViewById(R.id.score);
        intent = getIntent();
        String str = intent.getStringExtra(Common.COMMON);
        gson = new Gson();
        nearData = gson.fromJson(str, NearData.RowsDTO.class);

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_30_activity_details);
        init();
        initExit();

        fill();
    }

    private void fill() {
        Glide.with(DetailsActivity.this).load(OkHttpTool.URL+nearData.getImgUrl()).into(imgUrl);
        name.setText(nearData.getName());
        name1.setText(nearData.getName());
        address.setText(nearData.getAddress());
        avgCost.setText(String.valueOf(nearData.getAvgCost()));
        deliveryTime.setText(String.valueOf(nearData.getDeliveryTime()));
        distance.setText(String.valueOf(nearData.getDistance()));
        score.setText(String.valueOf(nearData.getScore()));



    }

    private void initExit() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DetailsActivity.this.finish();
            }
        });
    }


}